package main.java.org.gravity;

/*
 * Author: Fami
 * version: 0.1
 * File: osProcGui.java
 * Repo: https://code.google.com/p/osprocchecker/
 * License: MIT License
 * Desc: Class for invoking the OSProcChecker Gui 
 */

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class osProcGui {
	
	public static void osProcWindow(){
		
		JFrame frame = new JFrame("OSProcChecker");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLocationRelativeTo(null);
		frame.setSize(300, 500); 	//frame size following the contents
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
				
		JLabel label_title = new JLabel("OS Process Checker.");
		label_title.setBounds(85, 10, 200, 10);
		
		JLabel label_procName = new JLabel("Process Name: ");
		label_procName.setFont(new Font("Serif", Font.BOLD, 12));
		label_procName.setBounds(10, 50, 280, 10);
		
		JLabel label_status = new JLabel("click Scan Button to start the Listerner...");
		label_status.setFont(new Font("Serif", Font.BOLD, 11));
		label_status.setBounds(10, 120, 280, 10);

		final JTextField textField_procName = new JTextField();
		textField_procName.setBounds(100, 45, 150, 20);
		textField_procName.setBackground(Color.WHITE);
		
		final JTextArea textArea_note = new JTextArea();
		textArea_note.setBounds(10, 150, 260, 300);
		textArea_note.setEditable(false);
		textArea_note.setBackground(Color.BLACK);
		textArea_note.setForeground(Color.GREEN);
		
		JButton button_scan = new JButton("Scan");
		
		
		// Scan Button Function
		button_scan.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e_scan) {
				String proc_name = textField_procName.getText();
				if (proc_name.contentEquals("")){
					textArea_note.setText("");
					textArea_note.append("[INFO] Please enter the process name.");
				}else {
					textArea_note.setText("");
					textArea_note.append("[INFO] Scanning started....\n[INFO] Process Name: "+'"'+proc_name+'"'+"\n");
					if (procScanner.winScanner(proc_name).isEmpty()){
						textArea_note.append("[INFO] Process "+'"'+proc_name+'"'+" not found.");

					}else{
						textArea_note.append(procScanner.winScanner(proc_name));
						
					}
					
				}
			}
		});
		
		JButton button_stop = new JButton("Stop");
		// Stop Button Function
		button_stop.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e_stop) {
				textArea_note.setText("");
				textArea_note.append("Checker Listener Stop!!\n");
				
			}
		});
		
		JButton button_exit = new JButton("Exit");
		// Exit button function
		button_exit.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e_stop) {
				System.exit(0);		
			}
		});;
		
		button_scan.setBounds(10, 90, 80, 20);
		button_stop.setBounds(100, 90, 80, 20);
		button_exit.setBounds(190, 90, 80, 20);
		
		frame.add(panel);
		panel.add(label_title);
		panel.add(label_procName);
		panel.add(label_status);
		panel.add(button_scan);
		//panel.add(button_stop); //disabled as the listener features not yet developed
		panel.add(button_exit);
		panel.add(textField_procName);
		panel.add(textArea_note);
		
		frame.setVisible(true);

	}
}
